<?php

/**
 * This is the model class for table "vanbanphapluat".
 *
 * The followings are the available columns in table 'vanbanphapluat':
 * @property integer $id
 * @property string $tieude
 * @property string $noidung
 * @property string $file
 * @property string $from
 * @property string $to
 * @property integer $uid
 * @property integer $loai
 * @property integer $linhvuc
 * @property integer $coquan
 * @property integer $flag
 */
class Vanbanphapluat extends CActiveRecord {

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'vanbanphapluat';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('tieude, uid, flag,url', 'required'),
            array('uid, loai, linhvuc, coquan, flag', 'numerical', 'integerOnly' => true),
            array('tieude', 'length', 'max' => 500),
             array('url', 'length', 'max' => 300),
            array('file', 'length', 'max' => 100),
            array('noidung, from, to', 'safe'),
             array('file', 'file', 'types'=>'doc,docx,xls,xlsx,pdf','maxSize' => 4000000, 'allowEmpty' => true, 'tooLarge' => 'Hình ảnh không được vượt quá 4mb. Bạn phải giảm dung lượng file tải lên .'),
            // The following rule is used by search().
            // @todo Please remove those attributes that should not be searched.
            array('id, tieude, noidung, file, from, to, uid, loai, linhvuc, coquan, flag', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'tieude' => 'Tiêu đề',
            'noidung' => 'Nội dung',
            'file' => 'File đính kèm',
            'from' => 'Từ ngày',
            'to' => 'Đến ngày',
            'uid' => 'Uid',
            'loai' => 'Loại văn bản',
            'linhvuc' => 'Lĩnh vực',
            'coquan' => 'Cơ quan ban hành',
            'url' => 'Tên hiển thị url',
            'flag' => 'Trạng thái',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     *
     * Typical usecase:
     * - Initialize the model fields with values from filter form.
     * - Execute this method to get CActiveDataProvider instance which will filter
     * models according to data in model fields.
     * - Pass data provider to CGridView, CListView or any similar widget.
     *
     * @return CActiveDataProvider the data provider that can return the models
     * based on the search/filter conditions.
     */
    public function search() {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('tieude', $this->tieude, true);
        $criteria->compare('noidung', $this->noidung, true);
        $criteria->compare('file', $this->file, true);
        $criteria->compare('from', $this->from, true);
        $criteria->compare('to', $this->to, true);
        $criteria->compare('uid', $this->uid);
        $criteria->compare('loai', $this->loai);
        $criteria->compare('linhvuc', $this->linhvuc);
        $criteria->compare('coquan', $this->coquan);
        $criteria->compare('flag', $this->flag);
        $criteria->compare('url', $this->flag);
        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

    /**
     * Returns the static model of the specified AR class.
     * Please note that you should have this exact method in all your CActiveRecord descendants!
     * @param string $className active record class name.
     * @return Vanbanphapluat the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

}
